<?php namespace Clases;

class Valida{
    public static function validar($loginUsername,$password){
        $server = "itesm.mx";
        $connection = fsockopen($server, 110, $errno, $errstr, 30);
        if(!$connection) {
            return false;
        } else {
            $output = fgets($connection, 128);
            fputs($connection, "user $loginUsername\n");
            $output = fgets($connection, 128);
            fputs($connection, "pass $password\n");
            $output = fgets($connection, 128);
            $subout = substr($output, 0, 4);
            if($subout == "+OK ") {
                $loginFoundUser = 1;
            }
            else {
                $loginFoundUser = 0;
            }	   
            fputs($connection, "quit\n");
        }
        fclose($connection);
        return $loginFoundUser;
    }
}
?>
